<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="smallmuou&#39;s blog">
<meta property="og:url" content="http://smallmuou.gitee.io/blog/page/12/index.html">
<meta property="og:site_name" content="smallmuou&#39;s blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="smallmuou&#39;s blog">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://smallmuou.gitee.io/blog/page/12/"/>





  <title>smallmuou's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">smallmuou's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"><a href="https://github.com/smallmuou">https://github.com/smallmuou</a></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/06/06/2016-06-06-服务端API测试工具之JMeter/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/06/06/2016-06-06-服务端API测试工具之JMeter/" itemprop="url">服务端API测试工具之JMeter</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-06-06T00:00:00+08:00">
                2016-06-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/后端/" itemprop="url" rel="index">
                    <span itemprop="name">后端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>在互联化的时代浪潮里，服务端API变得无处不在，几乎每个公司都有会提供服务API给第三方调用，而服务API的测试也就提上日程，本文我们将介绍API测试工具JMeter，<a href="http://jmeter.apache.org" target="_blank" rel="noopener">JMeter</a>是Apache组织的开放源代码项目，它是功能和性能测试的工具. 本文将对Jmeter进行比较系统化的阐述.</p>
<h2 id="1-概述"><a href="#1-概述" class="headerlink" title="1. 概述"></a>1. 概述</h2><p>对于服务端API的测试，我们自然而然地想到，”发请求收回复”，因此想curl、postman都可以实现类似的功能，但面对批量性、关联性、压力测试等需求时，就显得不足，或者说无法完成，那么有没有一款软件能够实现呢？经过查找，发现了JMeter，<a href="http://jmeter.apache.org" target="_blank" rel="noopener">JMeter</a>是Apache组织的开放源代码项目，它是功能和性能测试的工具. 它包含了线程组、定时器、断言、元件、前缀处理器、后置处理器、监听器等，可以说功能非常强大. 下面我JMeter涉及到的一些词语进行描述:</p>
<ul>
<li>测试计划 - 根节点，可以理解为工程，其中配置了工程的基础信息，如jar包、各线程组运行机制等.一个测试计划可以包含多个线程组.</li>
<li>线程组 - 也可以称为用户组，指一组测试用例</li>
<li>逻辑控制器 - 对测试单元的逻辑控制，包含循环、随机等</li>
<li>配置元件 - 公共单元，如默认HTTP请求头、Cookie等</li>
<li>定时器 - 各个测试用例的调用顺序</li>
<li>前置处理器 - 在测试用例执行前预处理</li>
<li>Sampler - 采样器，具体的测试用例，包含FTP请求、HTTP请求</li>
<li>后置处理 - 在测试单元执行后对结果的处理</li>
<li>断言 - 对结果进行预定化验证</li>
<li>监听器 - 输出并分析结果</li>
</ul>
<h2 id="2-安装"><a href="#2-安装" class="headerlink" title="2. 安装"></a>2. 安装</h2><ul>
<li>进入<a href="http://jmeter.apache.org/download_jmeter.cgi" target="_blank" rel="noopener">JMeter下载界面</a>，下载相应版本JMeter，由于JMeter是利用Java实现的，因此需要先安装Java环境.</li>
<li>解压压缩包，并进入目前</li>
<li>类Unix请执行<code>jmeter.sh</code>，Windows用户请执行<code>jmeter.bat</code></li>
</ul>
<h2 id="3-DEMO"><a href="#3-DEMO" class="headerlink" title="3. DEMO"></a>3. DEMO</h2><p>本例将以授权接口作为测试用例.</p>
<ul>
<li>添加【线程组】<pre>
右键【测试计划】-> 添加 -> Threads(Users) -> 线程组
</pre></li>
<li>添加【HTTP请求默认值】<br><pre><br>右键【线程组】-&gt; 添加 -&gt; 配置元件 -&gt; HTTP请求默认值<br></pre><br>PS: 填写API请求的域名、端口等公共信息</li>
<li>添加【HTTP信息头管理器】<br><pre><br>右键【线程组】-&gt; 添加 -&gt; 配置元件 -&gt; HTTP信息头管理器<br></pre><br>PS: 填写API请求头公共信息，如Content-Type:application/json等</li>
<li>添加【察看结果树】<pre>
右键【线程组】-> 添加 -> 监听器 -> 察看结果树
</pre></li>
<li>添加【HTTP请求】<pre>
右键【线程组】-> 添加 -> Sampler -> HTTP请求
</pre>


</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/06/03/2016-06-03-Debian无法执行rc.local原因/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/06/03/2016-06-03-Debian无法执行rc.local原因/" itemprop="url">Debian无法执行rc.local原因</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-06-03T00:00:00+08:00">
                2016-06-03
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>今天在配置树莓派启动项的时候，发现无法执行<code>/etc/rc.local</code>中的命令，非常奇怪，后来网上搜索了下，发现原来是dash在作怪，具体怎么回事，我来细细讲述下.</p>
<h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><p>在正式讲述前，先普及下知识<code>bash</code>与<code>dash</code>:</p>
<ul>
<li>bash<pre>
bash 是一个为GNU计划编写的Unix shell。它的名字是一系列缩写：Bourne-Again SHell — 这是关于Bourne shell（sh）的一个双关语（Bourne again / born again）。Bourne shell是一个早期的重要shell，由史蒂夫·伯恩在1978年前后编写，并同Version 7 Unix一起发布。bash则在1987年由布莱恩·福克斯创造。
</pre></li>
<li>dash <pre>
Dash Shell 是一个Unix Shell，比Bash Shell 小的多，符合POSIX标准。Debian曾经采用/bin/bash的更改/bin/dash，目的使用更少的磁盘空间、提供较少的功能、获取更快的速度。但是后来经过shell脚本测试存在运行问题。因为原先在bash shell 下可以运行的shell script （shell 脚本），会出现一些意想不到的问题，不是100%的兼用。
Ubuntu继承了Debian，所以从Ubuntu 6.10开始默认是Dash Shell。
</pre>

</li>
</ul>
<h2 id="分析"><a href="#分析" class="headerlink" title="分析"></a>分析</h2><p>我们先来看下<code>/etc/rc.local</code>文件</p>
<pre>
osmc@smallmuou:~$ cat /etc/rc.local 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo modprobe bcm2835-v4l2

exit 0
</pre>

<p>通过上述我们可以看出，该脚本是通过<code>/bin/sh</code>来执行的，我们ls <code>/bin/sh</code></p>
<p><pre><br>osmc@smallmuou:~$ ls -al /bin/sh<br>lrwxrwxrwx 1 root root 4 Jun  2 21:03 /bin/sh -&gt; dash<br></pre><br>原来他真指向dash，我们编写shell脚本一般是以bash为标准，而dash与bash存在较大差异，因此就会出现无法执行问题.</p>
<h2 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h2><h4 id="sudo-dpkg-reconfigure-dash"><a href="#sudo-dpkg-reconfigure-dash" class="headerlink" title="sudo dpkg-reconfigure dash"></a>sudo dpkg-reconfigure dash</h4><p>选择NO，不使用Dash Shell。检查是否正确：<code>ls -l /bin/sh</code></p>
<h4 id="chmod-x-etc-rc-local"><a href="#chmod-x-etc-rc-local" class="headerlink" title="chmod +x /etc/rc.local"></a>chmod +x /etc/rc.local</h4>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/06/02/2016-06-02-外网环境下控制内网主机/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/06/02/2016-06-02-外网环境下控制内网主机/" itemprop="url">外网环境下控制内网主机</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-06-02T00:00:00+08:00">
                2016-06-02
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>很早就有这样一个想法: 通过远程控制内网主机，原来有尝试借助于路由器的端口映射或DMZ来实现，可是后面发现这并不现实，首先是假如有多级路由，那每个路由都要配置，非常麻烦，而且有些根路由，根本无法触及到;其次电信、联通等网络并不一定暴露公网IP给我们，因此外网根本访问不到（可以理解为我们处于一个大局域网下）；由于这种种原因，渐渐放弃了这个想法，直到有一天发现SSH反向连接这个东西. 当时一看到这个，就好像发现新大陆一样，无比兴奋，经过一段时间的折腾，终于找到了控制内网直接的好方案.</p>
<h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><ul>
<li><p>SSH正向连接 - 客户端连接服务端，并将服务端端口映射到客户端上</p>
<pre>
ssh -L [客户端IP或省略]:[客户端端口]:[服务器侧能访问的IP]:[服务器侧能访问的IP的端口] [登陆服务器的用户名@服务器IP] -p [服务器ssh服务端口（默认22）]
</pre>
</li>
<li><p>SSH反向连接 - 客户端连接服务端，并将客户端端口映射到服务器上<br><pre><br>ssh -R [服务器IP或省略]:[服务器端口]:[客户端侧能访问的IP]:[客户端侧能访问的IP的端口] [登陆服务器的用户名@服务器IP] -p [服务器ssh服务端口（默认22）]<br></pre><br>PS: 其中，服务器IP如果省略，则默认为127.0.0.1，只有服务器自身可以访问。指定服务器外网IP的话，任何人都可以通过[服务器IP:端口]来访问服务</p>
</li>
</ul>
<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><p>一般情况下，我们是使用ssh来连接远程主机的，其默认端口是22，下面我们来对他进行配置</p>
<h4 id="1-反向链接"><a href="#1-反向链接" class="headerlink" title="1. 反向链接"></a>1. 反向链接</h4><pre>
# 内网主机执行
ssh -RN 7023:localhost:22 server_user@server_ip
</pre>
PS: 本配置是指将内网主机端口22映射到服务器7023端口，接下来你可以在服务器执行`ssh -p7023 client_user@localhost`命令来接入内网主机，并进行控制

#### 2. 端口转发
通过上一步的配置，我们已经可以进行了远程控制，但不是很方便，我们需要登录服务器，再登录内网主机，显得很麻烦，有没有直接登录内网主机的办法？肯定有，方法如下:

* 方法一
<pre>
# 编辑服务端/etc/ssh/sshd_config
GatewayPorts yes
</pre>

<p>关于GatewayPorts说明如下:</p>
<pre>
Specifies whether remote hosts are allowed to connect to ports forwarded for the client.  By default, sshd(8)
             binds remote port forwardings to the loopback address.  This prevents other remote hosts from connecting to for-
             warded ports.  GatewayPorts can be used to specify that sshd should allow remote port forwardings to bind to non-
             loopback addresses, thus allowing other hosts to connect.  The argument may be ``no'' to force remote port for-
             wardings to be available to the local host only, ``yes'' to force remote port forwardings to bind to the wildcard
             address, or ``clientspecified'' to allow the client to select the address to which the forwarding is bound.  The
             default is ``no''.
</pre>


<ul>
<li>方法二<br><pre><h1 id="服务器执行"><a href="#服务器执行" class="headerlink" title="服务器执行"></a>服务器执行</h1>ssh -fCNL <em>:8023:localhost:7023 localhost<br></em></pre><br>PS: 将7023映射为外部可以访问的8023端口，这里的``很关键，如果不加，外部主机还是无法接入. 可以加入到开机启动项中，这样就完全自动化.</li>
</ul>
<h2 id="优化"><a href="#优化" class="headerlink" title="优化"></a>优化</h2><p>通过以上配置，基本实现了外网控制内网主机的方法，但我在操作的过程中，发现问题很多，特别是经常断线，而严重影响着使用，经过几天的努力，终于一一解决了，如下是遇到的问题及解决方案.</p>
<h3 id="1-SSH掉线"><a href="#1-SSH掉线" class="headerlink" title="1. SSH掉线"></a>1. SSH掉线</h3><p>相信用过SSH的童鞋会发现，但一段时间不操作后，SSH就卡死了，需要重新连接，对于我们来说非常麻烦，每次再控制前都得让客户端重新执行下SSH反向连接，体验非常差，经过Google发现已经有了解决方案，如下（可以参考<a href="http://www.coder4.com/archives/3751" target="_blank" rel="noopener">此文</a>）:</p>
<ul>
<li>客户端配置<pre>
#打开
sudo vim /etc/ssh/ssh_config
# 添加
ServerAliveInterval 20
ServerAliveCountMax 999
</pre></li>
<li>服务端配置<pre>
# 打开
sudo vim /etc/ssh/sshd_config
# 添加
ClientAliveInterval 30
ClientAliveCountMax 6
</pre>

</li>
</ul>
<p>PS: 经过上面的配置后，我发现SSH就很少断</p>
<h3 id="2-SSH断开自动重连"><a href="#2-SSH断开自动重连" class="headerlink" title="2. SSH断开自动重连"></a>2. SSH断开自动重连</h3><p>经过上一点的优化后，已经得到了大大的改善，但总是有断开的时候，那能否保证断开后重新连接上，我最先想到用守护进程去执行ssh，来保证ssh不会停止，而后面发现个更好的东西<code>autossh</code>:</p>
<pre>
autossh -N -R 7076:localhost:22 server_user@server_ip -i /home/client_user/.ssh/id_rsa
</pre>
详情参见[这里](http://www.oschina.net/translate/automatically-restart-ssh-sessions-and-tunnels-using-autossh)

### 3. 开机自动配置
为了保证重启后自动配置，需要添加开机启动项，这里使用service进行配置

##### (1) 配置service
sudo vim /etc/default/autossh

<pre>
AUTOSSH_POLL=60
AUTOSSH_FIRST_POLL=30
AUTOSSH_GATETIME=0
AUTOSSH_PORT=22000
SSH_OPTIONS="-N -R 2222:localhost:22 example.com -i /home/autossh/.ssh/id_rsa"
</pre>

<p>sudo vim /lib/systemd/system/autossh.service</p>
<pre>
[Unit]
Description=autossh
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=用户名
EnvironmentFile=/etc/default/autossh
ExecStart=
ExecStart=/usr/bin/autossh $SSH_OPTIONS
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target
</pre>

<h5 id="2-软连接"><a href="#2-软连接" class="headerlink" title="(2) 软连接"></a>(2) 软连接</h5><pre>
sudo ln -s /lib/systemd/system/autossh.service \
      /etc/systemd/system/autossh.service
</pre>

<h5 id="3-启动服务"><a href="#3-启动服务" class="headerlink" title="(3) 启动服务"></a>(3) 启动服务</h5><pre>
sudo systemctl daemon-reload # 重载
sudo systemctl start autossh # 启动
sudo systemctl status autossh # 查看状态
</pre>

<h5 id="4-开机启动"><a href="#4-开机启动" class="headerlink" title="(4) 开机启动"></a>(4) 开机启动</h5><pre>
sudo systemctl enable autossh
</pre>

<p>PS: 想要了解更详细的内容，可以访问<a href="http://logan.tw/posts/2015/11/15/autossh-and-systemd-service/" target="_blank" rel="noopener">这里</a></p>
<h3 id="4-centos6下autossh安装"><a href="#4-centos6下autossh安装" class="headerlink" title="4. centos6下autossh安装"></a>4. centos6下autossh安装</h3><p>通过yum发现无法找到autossh，原因是未启动<a href="http://xmodulo.com/how-to-set-up-rpmforge-repoforge-repository-on-centos.html" target="_blank" rel="noopener">Repoforge库</a>，解决方法如下</p>
<pre>
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum install autossh
</pre>

<h2 id="后续"><a href="#后续" class="headerlink" title="后续"></a>后续</h2><p>以上是针对SSH 22端口进行映射，其他端口原理一样，可以自由发挥</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/05/27/2016-05-27-快速守护你的进程/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/05/27/2016-05-27-快速守护你的进程/" itemprop="url">快速守护你的进程</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-05-27T00:00:00+08:00">
                2016-05-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>为了保证服务一直存在，需要对服务进行守护，以保证在服务挂了的情况下自动启动服务，该机制可以通过<code>守护进程</code>去实现，可以去Google，相信会出来一大pia，各种语言对应的templete都有，c、python、shell。。。这样一般对于开发者很有用，当时略显繁琐，后来发现有<code>daemon</code>命令，爽到爆.不信你往下看</p>
<pre>
StarnetdeMacBook-Pro:flask starnet$ daemon -r -- sleep 999
StarnetdeMacBook-Pro:flask starnet$ ps -e|grep sleep
53555 ??         0:00.00 daemon -r -- sleep 999
53556 ??         0:00.00 sleep 999
53563 ttys009    0:00.00 grep --color sleep
</pre>
PS: 没错，你没看错，就这么一句，含义是守护`sleep 999`进程，可以kill 53556试试.


## Install
<pre>
sudo brew install daemon
</pre>

<h2 id="Usage"><a href="#Usage" class="headerlink" title="Usage"></a>Usage</h2><ul>
<li>-name - 名称</li>
<li>-r - 被守护的进程一挂掉，就立即启动</li>
<li>…</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/05/12/2016-05-12-通过expect实现自动输入密码/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/05/12/2016-05-12-通过expect实现自动输入密码/" itemprop="url">通过expect实现自动输入密码</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-05-12T00:00:00+08:00">
                2016-05-12
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <pre>
#!/usr/bin/expect
spawn ssh root@192.168.61.223
expect "password:"
send "123456\r"
interact
</pre>

<p>expect是用于处理交互，通过它可以完成自动化交互. expect包含set,send,expect,spawn,interact命令.</p>
<ul>
<li>set - 设置参数</li>
<li>send - 用于向进程发送字符串</li>
<li>expect - 从进程接收特定格式字符串（支持通配符）</li>
<li>spawn - 启动新的进程</li>
<li>interact - 允许用户交互</li>
</ul>
<p>当然如果要通过传参方式把密码传入，则可以使用<code>$argv</code>来实现</p>
<p><pre><br>set pwd [lindex $argv 0]<br>send “$pwd\r”<br></pre><br>PS: 获取第一个参数</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/05/11/2016-05-11-关于xargs与alias矛盾/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/05/11/2016-05-11-关于xargs与alias矛盾/" itemprop="url">关于xargs与alias矛盾</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-05-11T00:00:00+08:00">
                2016-05-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>xargs和alias是UNIX/类UNIX下比较常用的命令，而且也非常好用；他们非常和谐的各自活着，可是有一天，有一个攻城狮把他俩凑在一起，于是他们吵架了，闹矛盾了. 我们一起来看看为何吵架？</p>
<h2 id="xargs"><a href="#xargs" class="headerlink" title="xargs"></a>xargs</h2><pre>
xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr] [-L number] [-n number [-x]] [-P maxprocs] [-s size] [utility [argument ...]]
</pre>

<p>xargs从标准输入读取内容，并将这些内容作为参数传递给utility，utility可以是命令或可执行文件.</p>
<pre>
echo 'hello'|xargs printf 
</pre>

<h2 id="alias"><a href="#alias" class="headerlink" title="alias"></a>alias</h2><pre>
alias [-p] [name[=value] ... ]
</pre>

<p>alias起到别名的作用，一般有两个作用，一个是缩短命令长度，二是起别名.</p>
<pre>
alias rvi="unrvi>/dev/null;udid|awk '/Serial Number/{print \$3}'|xargs rvictl -s"
alias ll='ls -al'
</pre>

<h2 id="矛盾"><a href="#矛盾" class="headerlink" title="矛盾"></a>矛盾</h2><p>在正常使用过程中，也许大家并不会觉得有什么坑，但是当两个合在一起用，就会出现. </p>
<pre>
alias pr='printf'
echo 'hello'|xargs pr
</pre>
PS: 按正常思路，应该是输出`hello`，可惜报出如下错误`pr: cannot open hello, No such file or directory`

查了下资料发现:

> alias属于bash的内部命令，外部命令是无法识别的，而xargs则是外部命令，可以通过which就可以知道是内部还是外部命令

那么问题总要解决，该如何解决，总不会在/usr/local/bin下创建个pr文件，这么繁琐的事肯定不干，于是继续搜索，终于还是找到解决方案:

<pre>
alias [-p] [name[=value] ...]
...
A trailing space in  value causes the next word to be checked for alias substitution when the alias is expanded.
</pre>
PS: 大致含义是当value后面加上一个空格，则下一个单词也会用alias一起替换

<pre>
alias xargs='xargs ' #此处加一空格
alias pr='printf'
echo 'hello'|xargs pr
</pre>
输出：

<pre>
hello
</pre>

<p>PS: 于是解决了矛盾，他俩可以欢快地在一起，不信你也试试.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/04/22/2016-04-22-Gitlab服务器迁移/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/04/22/2016-04-22-Gitlab服务器迁移/" itemprop="url">Gitlab服务器迁移</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-04-22T00:00:00+08:00">
                2016-04-22
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/版本管理/" itemprop="url" rel="index">
                    <span itemprop="name">版本管理</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近公司新批了一台GIT服务器（Dell T130），需要把原来Git服务器的数据迁移到新服务器.这里对迁移过程做个简单的记录.</p>
<h3 id="1-备份原GIT服务器的数据"><a href="#1-备份原GIT服务器的数据" class="headerlink" title="1. 备份原GIT服务器的数据"></a>1. 备份原GIT服务器的数据</h3><pre>
 gitlab-rake gitlab:backup:create RAILS_ENV=production
</pre>

<p>PS: 备份后的文件一般是位于/var/opt/gitlab/backups下, 文件名如1461165090_gitlab_backup.tar</p>
<h3 id="2-新服务器上安装与原服务器一样版本的Gitlab"><a href="#2-新服务器上安装与原服务器一样版本的Gitlab" class="headerlink" title="2. 新服务器上安装与原服务器一样版本的Gitlab."></a>2. 新服务器上安装与原服务器一样版本的Gitlab.</h3><p>这里说明下为什么要一样，原因应该是由于Gitlab自身的兼容性问题，高版本的Gitlab无法恢复低版本备份的数据.</p>
<h3 id="3-将步骤1生成的tar文件拷贝到新服务器上相应的backups目录下"><a href="#3-将步骤1生成的tar文件拷贝到新服务器上相应的backups目录下" class="headerlink" title="3. 将步骤1生成的tar文件拷贝到新服务器上相应的backups目录下"></a>3. 将步骤1生成的tar文件拷贝到新服务器上相应的backups目录下</h3><p>可以利用scp进行直接拷贝.</p>
<p><pre><br>scp username@src_ip:/var/opt/gitlab/backups/1461165090_gitlab_backup.tar /var/opt/gitlab/backups<br></pre><br>PS: username为原服务器的用户名，src_ip原服务器IP地址</p>
<h3 id="4-新服务器恢复数据"><a href="#4-新服务器恢复数据" class="headerlink" title="4. 新服务器恢复数据"></a>4. 新服务器恢复数据</h3><p><pre><br>gitlab-rake gitlab:backup:restore RAILS_ENV=production   BACKUP=1461165090<br></pre><br>PS：BACKUP的时间点必须与原服务器备份后的文件名一致</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/04/18/2016-04-18-如何理解依赖注入/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/04/18/2016-04-18-如何理解依赖注入/" itemprop="url">如何理解依赖注入</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-04-18T00:00:00+08:00">
                2016-04-18
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/后端/" itemprop="url" rel="index">
                    <span itemprop="name">后端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近接触了Spring、AngularJS，发现一个有趣的名称<code>依赖注入</code>，听起来非常高大上，一开始给蒙了，于是疯狂地Google，在几经波折后，终于有了一点感悟，现在把它记录下来，希望也能够给初学者一点提示.</p>
<h3 id="概念-通俗易懂"><a href="#概念-通俗易懂" class="headerlink" title="概念(通俗易懂)"></a>概念(通俗易懂)</h3><p>首先，理解下<code>依赖</code>，大白话说就是一个东西需要另一个东西，才能完成. 在Coding世界里，有一个类依赖另一个类，一个方法依赖另一个类方法等等. 注入就好比把某个东西注入到另一个容器中，合起来讲，<code>依赖注入</code>或者也可以叫<code>注入依赖</code>，就是把依赖注入到一个类中，即类中不直接写明依赖，而是通过传参等方式从外部引入.</p>
<h3 id="例子-加深理解"><a href="#例子-加深理解" class="headerlink" title="例子(加深理解)"></a>例子(加深理解)</h3><ul>
<li>背景<br>我们需要设计这样一个司机类，它需要依赖于各种车类. 我们也许会这样设计<pre>
public class Driver {    
  public drive() {
      //此处直接在类内部实例化对象
      Bus car = new Bus();
      car.run()
  }
}
</pre>

</li>
</ul>
<p>利用依赖注入改进后的类.</p>
<pre>
public class Driver {
    public Car mcar;

    //通过set方法把依赖类，从外部注入
    public setCar(Car car) {
        mcar = car;
    }

    public drive() {
        car.run()
    }
}
</pre>

<h3 id="为什么-非常重要"><a href="#为什么-非常重要" class="headerlink" title="为什么(非常重要)"></a>为什么(非常重要)</h3><p>任何一个东西的产生都有缘由，不可能无缘无故产生，人家西游记中的孙猴子怎么来的都有介绍，更何况<code>依赖注入</code>这么重要的东西；然而很多博文都直接介绍什么依赖注入，而没有道明为何有这个东西，即这个东西怎么来的. 导致我看了好多博文，都无法理解（也可能是我愚钝^_^）. 下面我来阐述下，引入依赖注入，其实是为了更OCP化，即开闭原则 —— 对扩展开放，对修改关闭. 试想下上面的例子改进前的代码，假如我新增一个火车类，那么我就要修改Driver类，这就是违背了OCP原则. 而如果采用改进后代码，你就可以不用修改Driver类，只要创建一个继承于Car的火车子类，并通过set方法把火车类注入到Driver中.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/04/14/2016-04-14-HTML5之SVG/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/04/14/2016-04-14-HTML5之SVG/" itemprop="url">HTML5之SVG</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-04-14T00:00:00+08:00">
                2016-04-14
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/前端/" itemprop="url" rel="index">
                    <span itemprop="name">前端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近在解析douban.fm网页时，发现一些图标绘制时用SVG，于是借机脑补下. SVG是HTML5中绘制矢量图的技术.SVG利用XML技术，非常容易理解，来个DEMO:</p>
<p><pre></pre></p>
<p><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200px" height="200px"><br/>    <circle cx="100" cy="100" r="50" style="stroke: black; fill: red;"/><br/></svg><br><br>PS: 画个圆，是不是很容易，比直接采用jpg、png等图片方便多了，而且还不会糊.</p>
<h3 id="引入方式"><a href="#引入方式" class="headerlink" title="引入方式"></a>引入方式</h3><p>方式|示例<br>|:–|:–<br>embed|embed src=”circle1.svg” type=”image/svg+xml”<br>object|object data=”circle1.svg” type=”image/svg+xml”<br>iframe|iframe src=”circle1.svg”<br>嵌入HTML|此处省略<br>a|a href=”circle1.svg”</p>
<h3 id="形状绘制"><a href="#形状绘制" class="headerlink" title="形状绘制"></a><a href="http://www.runoob.com/svg/svg-tutorial.html" target="_blank" rel="noopener">形状绘制</a></h3><p>形状|元素|属性<br>|:–<br><a href="http://www.runoob.com/svg/svg-rect.html" target="_blank" rel="noopener">矩形</a>|rect|(x,y) - 起点, width - 宽, height - 高, rx - 圆角x半径, ry - 圆角y半径<br><a href="http://www.runoob.com/svg/svg-circle.html" target="_blank" rel="noopener">圆</a>|circle|r - 半径，(cx,cy) - 圆心<br><a href="http://www.runoob.com/svg/svg-ellipse.html" target="_blank" rel="noopener">椭圆</a>|ellipse|rx - 半长轴，ry - 半短轴，(cx,cy) - 圆心<br><a href="http://www.runoob.com/svg/svg-line.html" target="_blank" rel="noopener">直线</a>|line|(x1, y1) - 起点，(x2,y2) - 终点<br><a href="http://www.runoob.com/svg/svg-polygon.html" target="_blank" rel="noopener">多边形</a>|polygon|points - 坐标集合，如points=”200,10 250,190 160,210”<br><a href="http://www.runoob.com/svg/svg-polyline.html" target="_blank" rel="noopener">折线</a>|polyline|points - 坐标集合，如points=”20,20 40,25 60,40 80,120 120,140 200,180”<br><a href="http://www.runoob.com/svg/svg-path.html" target="_blank" rel="noopener">路径</a>|path|M - 起点, L - 下一点, …(大写表示绝对定位，小写表示相对定位)</p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>名称|元素<br>|:–<br><a href="http://www.runoob.com/svg/svg-text.html" target="_blank" rel="noopener">文本</a>|text</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2016/04/08/2016-04-08-Tomcat编译及源码分析/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2016/04/08/2016-04-08-Tomcat编译及源码分析/" itemprop="url">Tomcat编译及源码分析</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-04-08T00:00:00+08:00">
                2016-04-08
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/前端/" itemprop="url" rel="index">
                    <span itemprop="name">前端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近在学习Java Web服务端架构，想从最原始的架构学起，于是选择了Servlet，而在学习Servlet必须用到Tomcat，于是想进一步深入了解Tomcat。Tomcat 服务器是一个免费的开放源代码的Web 应用服务器，属于轻量级应用服务器，在中小型系统和并发访问用户不是很多的场合下被普遍使用，是开发和调试JSP 程序的首选。</p>
<h3 id="1-编译源码"><a href="#1-编译源码" class="headerlink" title="1. 编译源码"></a>1. 编译源码</h3><ul>
<li>到apache官网或github搜索tomcat源码并下载，也可以直接点击<a href="https://github.com/apache/tomcat" target="_blank" rel="noopener">此下载</a>，</li>
<li>安装ant命令，<code>sudo brew install ant</code></li>
<li>进入tomcat目录，并执行<code>ant</code></li>
<li>等待编译成功，成功后目标文件默认输出到output目录下</li>
<li>进入output/build，这是目录结构<pre>
drwxr-xr-x   9 starnet  staff  306 Apr  8 09:55 .
drwxr-xr-x   7 starnet  staff  238 Apr  8 09:56 ..
drwxr-xr-x  26 starnet  staff  884 Apr  8 09:54 bin
drwxr-xr-x  13 starnet  staff  442 Apr  8 09:55 conf
drwxr-xr-x  27 starnet  staff  918 Apr  8 09:54 lib
drwxr-xr-x   8 starnet  staff  272 Apr  8 09:55 logs
drwxr-xr-x   2 starnet  staff   68 Apr  8 09:54 temp
drwxr-xr-x   7 starnet  staff  238 Apr  8 09:54 webapps
drwxr-x---   3 starnet  staff  102 Apr  8 09:55 work
</pre></li>
<li>执行./bin/startup.sh<pre>
bogon:build starnet$ ./bin/startup.sh 
Using CATALINA_BASE:   /Users/starnet/Projects/tomcat/output/build
Using CATALINA_HOME:   /Users/starnet/Projects/tomcat/output/build
Using CATALINA_TMPDIR: /Users/starnet/Projects/tomcat/output/build/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
Using CLASSPATH:       /Users/starnet/Projects/tomcat/output/build/bin/bootstrap.jar:/Users/starnet/Projects/tomcat/output/build/bin/tomcat-juli.jar
Tomcat started.
</pre></li>
<li>点击此访问:<a href="http://localhost:8080，若能看到tomcat信息，那恭喜你，成功了" target="_blank" rel="noopener">http://localhost:8080，若能看到tomcat信息，那恭喜你，成功了</a>.</li>
</ul>
<h3 id="2-阅读源码"><a href="#2-阅读源码" class="headerlink" title="2. 阅读源码"></a>2. 阅读源码</h3><ul>
<li>安装Eclipse软件</li>
<li>新建Java Project</li>
<li>从File System进行import，选择tomcat源码目录</li>
<li>确定导入</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/11/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/11/">11</a><span class="page-number current">12</span><a class="page-number" href="/blog/page/13/">13</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/20/">20</a><a class="extend next" rel="next" href="/blog/page/13/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">smallmuou</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">197</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/smallmuou" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-globe"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">smallmuou</span>

  
</div>

    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <span id="busuanzi_container_site_pv">总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
